﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GistDescriptor.Tools
{
    public class Bucket
    {
        private Item _root;

        public Bucket()
        {
            _root = new Item();
	        _root.next = null;

        }
    
        public Item root
        {
            get
            {
                return _root;
            }
            set
            {
                _root = value;
            }
        }

        public void push(String e)
        {
           Item newItem = new Item();
	       newItem.element = e;
	        if(!isEmpty())
	        {
		        newItem.next = _root.next;
	        }
	        _root.next = newItem;
        }

        public String pop()
        {
            if(isEmpty()) return " ";
	        String element = _root.next.element;
	        _root.next = _root.next.next;
	        return element;

        }

        public List<String> toArray()
        {
            List<String> elementList = new List<String>();
	        Item iter = new Item();
	        iter.next = _root.next;
	        while(!iter.next.Equals(null))
	        {
	        	iter = iter.next;
	        	elementList.Add(iter.element);
	        }
	        return elementList;

        }

        public bool isEmpty()
        {
            if (root.next.Equals(null)) return true;
            else return false;

        }
    }
}
